#!/usr/bin/env python
# encoding: utf-8
"""
banner.py

Created by Manabu Terada on 2009-09-24.
Copyright (c) 2009 CMScom. All rights reserved.
"""

from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

class BannerView(BrowserView):
    
    template = ViewPageTemplateFile('banner.pt')

    def __call__(self):
        context = self.context
        # is_anon = getMultiAdapter((context, self.request),
        #                                  name=u'plone_portal_state').anonymous()
        # if is_anon:
        # portal_state = getMultiAdapter((context, self.request),
        #                                  name=u'plone_portal_state')
        tools = getMultiAdapter((context, self.request), name=u'plone_tools')
        mtool = tools.membership()
        checkPermission = mtool.checkPermission
        is_permission = checkPermission('Modify portal content', context)
        if not is_permission:
            context.request.RESPONSE.redirect(context.getRemoteUrl())
            return
        else:
            return self.template()
